package com.docjohnson.pamphlet.models;

import static com.docjohnson.pamphlet.utils.JsonConstants.BACKGROUND;
import static com.docjohnson.pamphlet.utils.JsonConstants.CONTENT;
import static com.docjohnson.pamphlet.utils.JsonConstants.ID;
import static com.docjohnson.pamphlet.utils.JsonConstants.PAMPHLETIMAGE;
import static com.docjohnson.pamphlet.utils.JsonConstants.TRANSITION_IMAGE;

import java.io.Serializable;

import org.json.JSONException;
import org.json.JSONObject;

import com.docjohnson.pamphlet.utils.Constants;

@SuppressWarnings("serial")
public class Pamphlet implements Serializable {

	private int id;
    private String name;
    
    private String localImagePath;
    private String remoteImagePath;
    private String localBackgroundPath;
    private String remoteBackgroundPath;
    private String localTransitionImagePath;
    private String remoteTransitionmagePath;
    
    private String header;
    private String content;
    private String favourites;
    
    private String prodPage;
    private String anim;
    
    public int inSampleSize = 1;

    public Pamphlet(JSONObject json) {
    	parseJson(json);
    }

    public int getId() {
    	return id;
    }
    
    public String getName() {
        return name;
    }

    public String getLocalImagePath() {
        return localImagePath;
    }

    public String getLocalBackgroundPath() {
        return localBackgroundPath;
    }
    
    public String getRemoteImagePath() {
        return remoteImagePath;
    }

    public String getRemoteBackgroundPath() {
        return remoteBackgroundPath;
    }
    
    public String getRemoteTransitionImagePath(){
    	return remoteTransitionmagePath;
    }

    public String getHeader() {
        return header;
    }
    
    public String getContent() {
    	return content;
    }
    
    public String getFavourites() {
    	return favourites;
    }

    public String getProdPage() {
        return prodPage;
    }

    public String getAnim() {
        return anim;
    }
    
    public String getLocalTransitionImagePath(){
    	return localTransitionImagePath;
    }
    
    public void setLocalImagePath(String path) {
    	localImagePath = path;
    }
    
    public void setLocalBackgroundPath(String path) {
    	localBackgroundPath = path;
    }
    
    public void setLocalTransitionImagePath(String path){
    	this.localTransitionImagePath = path;
    }

    public void parseJson(JSONObject pamphlet) {
    	try {
			remoteBackgroundPath = pamphlet.getString(BACKGROUND);
			remoteImagePath = pamphlet.getString(PAMPHLETIMAGE);
			remoteTransitionmagePath = pamphlet.optString(TRANSITION_IMAGE);
			
			id = pamphlet.getInt(ID);
			
			content = pamphlet.getString(CONTENT);
			localImagePath = Constants.CACHE_PAMPHLETS_DIR + "" + id + "/image_" + id + ".jpg";
			localBackgroundPath =  Constants.CACHE_PAMPHLETS_DIR + "" + id + "/background_" + id + ".jpg";
			localTransitionImagePath =  Constants.CACHE_PAMPHLETS_DIR + "" + id + "/transition_" + id + ".jpg";
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
}